import validator from '../behaviors/validator';

Component({
  externalClasses: ['tag-extra-class', 'tag-selected-class', 'tag-icon-extra-class'],
  behaviors: [validator],
  properties: {
    // 标签标识
    name: String,
    cell: Object,
    // 标签颜色
    type: {
      type: String,
      value: 'touch',
      options: ['reading', 'touch']
    },
    disable: Boolean,
    // 标签形状
    shape: {
      type: String,
      value: 'square',
      options: ['square', 'circle']
    },
    // 是否为选中态
    select: Boolean,
    // 是否镂空
    plain: Boolean,
    // 标签大小
    size: {
      type: String,
      value: 'medium',
      options: ['large', 'medium', 'mini', 'super-mini']
    },
    location: {
      type: String,
      value: 'left',
      options: ['left', 'right']
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      // console.log(this.properties.name);
    },
  },
  methods: {
    handleTap() {
      if (this.data.disable) {
        return
      }

      let options = {
        name: this.data.name,
        cell: this.data.cell,
        select: this.data.select
      };
      this.triggerEvent('tagTap', options, {
        bubbles: true,
        composed: true
      });
    }
  }
});